package com.zhongkun.datahome.web.app;

import com.zhongkun.datahome.common.annotation.Log;
import com.zhongkun.datahome.common.core.domain.R;
import com.zhongkun.datahome.common.enums.BusinessType;
import com.zhongkun.datahome.service.req.cmd.appointment.AppointmentCancelCmd;
import com.zhongkun.datahome.service.req.cmd.appointment.AppointmentJoinCmd;
import com.zhongkun.datahome.service.req.cmd.appointment.AppointmentViewCmd;
import com.zhongkun.datahome.service.res.appointment.AppointmentVo;
import com.zhongkun.datahome.service.service.IAppointmentService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.apache.ibatis.annotations.Param;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;

/**
 * @Author: MinKun
 * @Date: Created in 2025/6/26
 * @Description:
 */
@Api("小程序预约接口")
@RestController
@RequestMapping("/app/appointment")
@Slf4j
public class AppAppointmentController {

    @Resource
    private IAppointmentService appointmentService;

    @ApiOperation("参与预约")
    @Log(title = "参与预约", businessType = BusinessType.INSERT)
    @PostMapping("joinAppointment")
    public R<Void> joinAppointment(@RequestBody AppointmentJoinCmd cmd) {
        appointmentService.joinAppointment(cmd);
        return R.ok();
    }

    @ApiOperation("取消预约")
    @Log(title = "取消预约", businessType = BusinessType.UPDATE)
    @PostMapping("cancelAppointment")
    public R<Void> cancelAppointment(@RequestBody AppointmentCancelCmd cmd) {
        appointmentService.cancelAppointment(cmd);
        return R.ok();
    }

    @ApiOperation("查询指定房产的预约详情")
    @GetMapping("queryMatchAppointment")
    public R<AppointmentVo> queryMatchAppointment(@RequestParam Long customerHouseId) {
        return R.ok(appointmentService.queryMatchAppointment(customerHouseId));
    }

    @ApiOperation("查询预约配置")
    @GetMapping("queryAppointmentView")
    public R<AppointmentViewCmd> queryAppointmentView(@Param("id") Long id, Long houseId) {
        return R.ok(appointmentService.queryAppointmentView(id, houseId));
    }
}
